Imports KanBan.Pgd.Infrastructure.Exceptions
Imports NHibernate.Criterion
Imports KanBan.Pgd.Domain.Entities
Imports NHibernate

Namespace Repositories

    Public Class ProfileRepository
        Inherits RepositoryBase(Of Profile)

        Public Function GetAllByArea(ByVal areaId As Guid) As IEnumerable(Of Profile)

            Try

                Dim session As ISession = NHibernateHelper.GetCurrentSession()
                Dim entities As IEnumerable(Of Profile) = New List(Of Profile)

                entities = session _
                    .CreateCriteria(GetType(Profile)) _
                    .Add(Restrictions.Eq("IsDeleted", False)) _
                    .CreateAlias("Area", "a") _
                    .Add(Restrictions.Eq("a.Id", areaId)) _
                    .List(Of Profile)()

                Return entities

            Catch ex As Exception

                Throw New TechnicalException(String.Format("Error while trying to 'GetAllByArea' entities of type = {0} - Details: {1}", _
                                                                            GetType(Profile).ToString(), ex.Message), ex.InnerException)

            End Try

        End Function

    End Class

End Namespace
